﻿//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon Company Limited.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////
#include "CmdTypeProperty.h"
#include "CommandIds.h"
#include "CommandRegister.h"
#include "IDocument.h"
#include "UiDocumentViewUtils.h"
#include "CommandParameters.h"
#include "IUiDocumentViewManager.h"

#include "FamilyTypeDialogUtils.h"

#include "EnableCompileWarning_The_LAST_IncludeInCpp.h" 


using namespace gcmp;
using namespace Sample;

REGISTER_COMMAND(CmdTypeProperty)

CmdTypeProperty::CmdTypeProperty()
    :CommandBase(COMMAND_SHOW_TYPE_PARAMETERS)
{
}

bool CmdTypeProperty::IsEnabled() const
{
    IDocument *pDocument = UiDocumentViewUtils::GetCurrentDocument();

    return false;
}

bool CmdTypeProperty::IsVisible() const
{
    return UiDocumentViewUtils::GetCurrentDocument() != nullptr;
}

gcmp::OwnerPtr<gcmp::IAction> CmdTypeProperty::ExecuteCommand(const gcmp::CommandParameters& cmdParams)
{
    auto itr = cmdParams.find(L"ParamTypeId");
    DBG_WARN_AND_RETURN_NULLPTR_UNLESS(itr != cmdParams.end(), L"缺失ParamTypeId参数", L"GDMP", L"2023-12-05");
    Int64 paramTypeId = (*itr).second.AsInt64();
    DBG_WARN_AND_RETURN_NULLPTR_UNLESS(paramTypeId >= 0, L"ParamTypeId参数无效", L"GDMP", L"2023-12-05");
    ElementId typeId(paramTypeId);

    IUiDocument* pCurDoc = IUiDocumentViewManager::Get()->GetCurrentUiDocument();
    DBG_WARN_AND_RETURN_NULLPTR_UNLESS(pCurDoc != nullptr, L"没有当前的UIDoc", L"GDMP", L"2023-10-20");
    // 此示例代码响应EditFrameInstanceTypeParametersCommand.cpp文件发送的"ShowTypeParametersCmd"命令，
    // 通过族类型（IInstanceType）的elementId对该类型（IInstanceType）的参数进行显示或编辑。
    Sample::FamilyTypeDialogUtils::ShowEditTypeDialogInternal(pCurDoc, typeId);

    return nullptr;
}
